﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace PBO.Data
{
    public class BaseStats : IStats
    {
        //Hidden Power Sort
        public readonly static StatType[] Types = { StatType.Hp, StatType.Atk, StatType.Def, StatType.Speed, StatType.SpAtk, StatType.SpDef };

        #region Fun

        private int[] stats = new int[6];

        public BaseStats() : this(0) { }

        public BaseStats(int value)
        {
            stats = Enumerable.Repeat<int>(value, 6).ToArray();
        }

        public BaseStats(IStats stats)
        {
            SetValue(stats);
        }

        public void SetAll(int value)
        {
            for (int i = 0; i < stats.Length; i++)
            {
                stats[i] = value;
            }
        }

        public void SetValue(IStats stats)
        {
            foreach (StatType stat in Types)
            {
                this[stat] = stats[stat];
            }
        }

        public void SetValue(int[] array)
        {
            for (int i = 0; i < Types.Length && i < array.Length; i++)
            {
                this[i] = array[i];
            }
        }

        #endregion

        #region IStats

        public int this[StatType index]
        {
            get { return this[(int)index]; }
            set { this[(int)index] = value; }
        }

        public int this[int index]
        {
            get
            {
                if (index >= 0 && index < stats.Length)
                {
                    return stats[(int)index];
                }
                return 0;
            }
            set
            {
                if (index >= 0 && index < stats.Length)
                {
                    stats[(int)index] = value;
                }
            }
        }

        public int Hp
        {
            get { return stats[0]; }
        }
        public int Atk
        {
            get { return stats[1]; }
        }
        public int Def
        {
            get { return stats[2]; }
        }
        public int Speed
        {
            get { return stats[3]; }
        }
        public int SpAtk
        {
            get { return stats[4]; }
        }
        public int SpDef
        {
            get { return stats[5]; }
        }

        #endregion

        #region IEnumerator

        public IEnumerator<int> GetEnumerator()
        {
            foreach (int value in stats)
            {
                yield return value;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.stats.GetEnumerator();
        }

        #endregion

        #region IEquatable

        public bool Equals(IStats other)
        {
            foreach (StatType stat in Types)
            {
                if (this[stat] != other[stat]) return false;
            }
            return true;
        }

        #endregion

        #region ICloneable

        public object Clone()
        {
            return new BaseStats(this);
        }

        #endregion
    }



    public class BaseStats2
    {



        public int Hp { get; set; }

        public int Atk { get; set; }

        public int Def { get; set; }

        public int Speed { get; set; }

        public int SpAtk { get; set; }

        public int SpDef { get; set; }


    }




}